package com.sky.controller.admin;

import com.sky.dto.PageQuery;
import com.sky.result.PageResult;
import com.sky.result.Result;
import com.sky.service.impl.UserServiceImpl;
import com.sky.vo.UserActionLogVO;
import com.sky.vo.UserInfoVO;
import io.swagger.annotations.Api;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController("adminUserController")
@Api(tags = "管理端-用户的相关接口")
@Slf4j
@RequestMapping("/admin/user")
public class UserController {
    @Autowired
    private UserServiceImpl userService;

    /**
     * 分页查询用户列表
     * @param pageQuery
     * @return
     */
    @GetMapping()
    public Result<PageResult> pageQuery(PageQuery pageQuery){
       PageResult result=userService.pageQuery(pageQuery);
       return Result.success(result);
    }

    /**
     * 根据id获取当前用户的详细信息
     * @param id
     * @return
     */
    @GetMapping("/current/{id}")
    public Result<UserInfoVO> currentUser(@PathVariable Integer id){
        UserInfoVO userInfoVO=userService.currentUser(id);
        return Result.success(userInfoVO);
    }

    /**
     * 根据id获取当前用户的行为
     * @param id
     * @return
     */
    @GetMapping("/logs/{id}")
    public Result logs(@PathVariable Integer id){
       List<UserActionLogVO> logs=userService.logs(id);
       return Result.success(logs);
    }
}
